<template>
  <div class="tab-bar-item" @click="itemClick">
    <slot name="item-icon" v-if="!isActive"></slot>
    <slot name="item-icon-active" v-else></slot>
    <div :style="isFont">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>
<script>
export default {
  name: "TabBarItem",
  props: {
    link: {
      type: String
    },
    activeFont: {
      default: "pink"
    }
  },
  methods: {
    itemClick() {
      // 加一层判断，如果是重复点击相同的路由，不用跳转
      if (this.$route.path !== this.link) {
        // 跳转路由
        this.$router.push(this.link)
      }
    }
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.link) !== -1
    },
    isFont() {
      return this.isActive ? { color: this.activeFont } : {}
    }
  }
}
</script>
<style scoped>
.tab-bar-item {
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 14px;
}

.tab-bar-item img {
  width: 24px;
  height: 24px;
  vertical-align: middle;
  margin-bottom: 2px;
}
</style>